<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="../tpl/head.jsp"%>
<div class="container" id="app">
    <dl class="layui-card">
        <dd class="layui-card-body">
            <dl class="layui-row layui-form">
                <dd class="layui-col-md3">
                    <div class="layui-col-xs2 text-right padding-right height-large">
                        <text>日期</text>
                    </div>
                    <div class="layui-col-xs10">
                        <input type="text" class="layui-input" name="allTime" id="allTime" placeholder="开始 到 结束">
                    </div>
                </dd>
                <dd class="layui-col-md2 layui-col-xs12">
                    <div class="layui-col-xs4 text-right padding-right height-large">
                        <text>类型</text>
                    </div>
                    <div class="layui-col-xs8">

                        <!--<input type="checkbox" name="type[]" title="更" checked value="更">-->
                        <!--<input type="checkbox" name="type[]" title="增" checked value="增">-->
                        <!--<input type="checkbox" name="type[]" title="删" checked value="删">-->

                        <div id="type" class="xm-select-demo"></div>
                    </div>
                </dd>
                <dd class="layui-col-md2  layui-col-xs12">
                    <div class="layui-col-xs4 text-right padding-right height-large">
                        <text>表名</text>
                    </div>
                    <div class="layui-col-xs8">
                        <div id="tableName" class="xm-select-demo"></div>
                    </div>
                </dd>

                <dd class="layui-col-md3  layui-col-xs12">
                    <div class="layui-col-xs4 text-right padding-right height-large">
                        <text>操作人信息</text>
                    </div>
                    <div class="layui-col-xs8"><input type="text" name="userName" class="layui-input" value="" placeholder="编号，用户名"></div>
                </dd>

                <dd class="layui-col-md2">
                    <button class="layui-btn margin-left" lay-submit lay-filter="sksearch">查询</button>
                    <button class="layui-btn btn-danger margin-left" id="getnowlog">生成当天日志</button>
                </dd>
            </dl>
        </dd>
        <dd>
            <table class="layui-hide" id="sklogtable"></table>
        </dd>
    </dl>
</div>
<%@ include file="../tpl/foot.jsp"%>
<script>
    layui.use(["form", "table","laydate"], async function() {
        let form = layui.form,
            table = layui.table,
            laydate=layui.laydate,
            $=layui.jquery

        /*
         * 数据初始定义
        */
        let val = [
                {name: '更新', value: "update(更新)", selected: true},
                {name: '新增', value: "insert(新增)", selected: true},
                {name: '删除', value: "delete(删除)", selected: true},
            ],
            val2 = []
                // {name: '表1', value: "表1"},
                // {name: '表2', value: "表2"},
                // {name: '表3', value: "表3"},



        /*
        * 日志类
        */
        class SKLOG {
            constructor() {}
            async getapi(url){
                return await fetch(url).then(res=>res.json())
            }
            settable(option) {
                return table.render(option)
            }
            getjson(data){
                $.ajax({
                    type : 'get'
                    //  url : 'resource/getTree',
                    //String taskId, Map<String, Object> variables, String activityId,String comment
                    ,data:data,
                    url:'logdb/queryByPage',
                    dataType:"json",
                    /*  contentType: 'application/json',*/
                    async:false,
                    success : function (da) {
                        if(da.status==200 ){
                            console.log(da)
                        }
                    },
                    error: function(data) {
                        // layer.msg("获取失败!");
                    }
                });
            }
            formsubmit() {
                let that = this

                return form.on('submit(sksearch)',async data=> {
                    let myload=layui.layer.load()
                    let obj={
                        inTime:data.field.allTime.split(",")[0],
                        endTime:data.field.allTime.split(",")[1],
                        userName:data.field.userName,
                        type:data.field.type,
                        tableName:data.field.tableName,
                    },
                        options = {
                            elem: '#sklogtable',
                            url:"logdb/queryByPage",
                            where:obj,
                            cols: [
                                [
                                    { type: 'numbers', width: 50, title: '序号' },
                                    { field: 'userName', width: 200, title: '操作人', sort: true },
                                    { field: 'type', width: 100, title: '操作类型', sort: true },
                                    { field: 'inTime', width: 100, title: '操作时间', sort: true },
                                    { field: 'tableName', width: 250, title: '模块', sort: true },
                                    { field: 'params', title: '信息' }
                                ]
                            ]
                            ,page: true
                            ,height:window.innerHeight-55
                        }



                    console.log(options)

                    that.settable(options)
                    layer.close(myload);
                    return false;
                })
            }
            setlaydata(obj){
                return  laydate.render(obj)
            }
            getxmselect(el, name, data) {
                return xmSelect.render({
                    el: el,
                    name: name,
                    data: data,
                    tips: '不能为空',
                })
            }
        }
        //流程调用
        let mylog = new SKLOG()

        /*
        DOM操作
        */

        // 查询事件提交
        mylog.formsubmit()
        //日期选择
        mylog.setlaydata({
            elem: '#allTime'
            ,type: 'datetime'
            ,max: +new Date()
            ,range: ['', ""]
        })
        //下拉类型设置
        mylog.getxmselect("#type", "type", val)
        //下拉表名设置
        let tablelist=getdictionary(6,61)
        for(item of tablelist){
            val2.push({name: item.name, value: item.code})
        }
        mylog.getxmselect("#tableName", "tableName", val2)
    //    生成日志
        $("#getnowlog").click(function () {
            $.ajax({
                type : 'get',
                //  url : 'resource/getTree',
               // data:{"id":data.id,"status":data.status},
                url:'logdb/insert',
                dataType:"json",
                /*  contentType: 'application/json',*/
                async:false,
                success : function (da) {

                        layui.layer.msg("生成日志任务成功，稍后进行日志查询！")
                },
                error: function(data) {
                    // layer.msg("获取失败!");
                }
            });
        })
    })

  // let obj=  getdictionary(6,61);
  //   console.log(obj);
</script>